package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.MesProducePassStationDetail;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.MesProducePassStationDetailDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2022-03-30 15:31:01
 */
public class MesProducePassStationDetailConverts {

    private static Logger LOG = LoggerFactory.getLogger(MesProducePassStationDetailConverts.class);

    public static List<MesProducePassStationDetailDTO> convert(List<MesProducePassStationDetail> mesProducePassStationDetailList) {
        if (CollectionUtils.isEmpty(mesProducePassStationDetailList)) {
            return Collections.EMPTY_LIST;
        }

        List<MesProducePassStationDetailDTO> mesProducePassStationDetailListResult = Lists.newArrayList();
        for (MesProducePassStationDetail mesProducePassStationDetail : mesProducePassStationDetailList) {
            mesProducePassStationDetailListResult.add(convert(mesProducePassStationDetail));
        }
        return mesProducePassStationDetailListResult;
    }

    public static MesProducePassStationDetailDTO convert(MesProducePassStationDetail mesProducePassStationDetail) {
        try {
            return BeanUtils.copy(mesProducePassStationDetail, MesProducePassStationDetailDTO.class);
        } catch (Exception e) {
            LOG.error("MesProducePassStationDetail到MesProducePassStationDetailDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "MesProducePassStationDetail到MesProducePassStationDetailDTO转换失败", e);
        }
    }

    public static MesProducePassStationDetail convert(MesProducePassStationDetailDTO mesProducePassStationDetailDTO) {
        try {
            return BeanUtils.copy(mesProducePassStationDetailDTO, MesProducePassStationDetail.class);
        } catch (Exception e) {
            LOG.error("MesProducePassStationDetailDTO到MesProducePassStationDetail转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "MesProducePassStationDetailDTO到MesProducePassStationDetail转换失败", e);
        }
    }
}